package com.nbgroup.controller;

import com.nbgroup.annotation.HttpMethod;
import com.nbgroup.pojo.Course;
import com.nbgroup.pojo.common.PageBean;
import com.nbgroup.pojo.common.Result;
import com.nbgroup.pojo.dto.PageCourseDTO;
import com.nbgroup.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequiredArgsConstructor
@Api(tags = "课程管理")
public class CourseController {
private final CourseService courseService;

    @HttpMethod("GET")
@GetMapping("/clues/course/list")
    @ApiOperation("分页搜索")
    public PageBean coursePageQuery(PageCourseDTO pageCourseDTO){
    PageBean pageBean=courseService.coursePageQuery(pageCourseDTO);
    return pageBean;
    }

    @HttpMethod("POST")
    @PostMapping("/clues/course")
    @ApiOperation("添加课程")
    public Result addCourse(@RequestBody Course course){
    courseService.addCourse(course);
    return Result.success();
    }

    @HttpMethod("GET")
    @GetMapping("/clues/course/{id}")
    @ApiOperation("查询回显")
    public Result queryCourse(@PathVariable Long id){
    Course course = courseService.queryCourse(id);
    return Result.success(course);
    }

    @HttpMethod("PUT")
    @PutMapping("/clues/course")
    @ApiOperation("修改课程")
    public Result updateCourse(@RequestBody Course course){
    courseService.updateCourse(course);
    return Result.success();
    }

    @HttpMethod("DELETE")
    @DeleteMapping("/clues/course/{ids}")
    @ApiOperation("删除课程")
    public Result deleteCourse(@PathVariable List<Long> ids){
    courseService.deleteCourse(ids);
    return Result.success();
    }
}
